package cn.darkfire.web.Controller;

import cn.darkfire.web.Utils.ImageUtils;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;


@WebServlet(name="getImg.do")
public class VerityCodeController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("image/png");
        BufferedImage img = ImageUtils.getInstance().initImage();
        ImageIO.write(img,"png",resp.getOutputStream());
        req.getSession().setAttribute("code",ImageUtils.getInstance().getCode());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
